InĀ [1]:
from pathlib import Path
from compare import ReferenceComparer, get_last_two_commits

Find commits to compare¶

By default, the notebook compares last two commits(ref1hash is the older one and ref2hash is the newer one). You can customise this by changing the ref1_hash and ref2_hash variables or by providing REF1_HASH and REF2_HASH commit values. You can also provide custom spectrum paths for the two hashes with respect to the root directory for that commit.

InĀ [2]:
import os

ref1_hash = os.getenv('REF1_HASH')
ref2_hash = os.getenv('REF2_HASH')

if not (ref1_hash and ref2_hash):
    ref1_hash, ref2_hash = get_last_two_commits()

if not (ref1_hash and ref2_hash):
    raise ValueError("Could not get commit hashes.")
    

if os.getenv('CUSTOM_REF1_SPECTRUM_PATH'):
    custom_ref1_spectrum_path = os.getenv('CUSTOM_REF1_SPECTRUM_PATH')
else:
    custom_ref1_spectrum_path = 'tardis/spectrum/tests/test_spectrum_solver/test_spectrum_solver/TestSpectrumSolver.h5'

if os.getenv('CUSTOM_REF2_SPECTRUM_PATH'):
    custom_ref2_spectrum_path = os.getenv('CUSTOM_REF2_SPECTRUM_PATH')
else:
    custom_ref2_spectrum_path = 'tardis/spectrum/tests/test_spectrum_solver/test_spectrum_solver/TestSpectrumSolver.h5'
InĀ [3]:
ref1_hash, ref2_hash
Out[3]:
('84e768462f20f09fbccc05625cdcc1d8ffbe404c',
 '31a79873a86abb5f428d4361134da6c3f1501f07')

Example Values¶

Below are example values you can test the notebook with.

InĀ [4]:
# ref1_hash="170f1a2c0d8c6db518a4b9a0f4cb9b657aaa61b6"
# ref2_hash="d9fd3bb659d185bd9ece10b8e2175cf497ea84c5"
# custom_ref1_spectrum_path = 'tardis/spectrum/tests/test_spectrum_solver/test_spectrum_solver/TestSpectrumSolver.h5'
# custom_ref2_spectrum_path = 'test_spectrum_solver/test_spectrum_solver/TestSpectrumSolver.h5'

Initialise the ReferenceComparer class¶

InĀ [5]:
comparer = ReferenceComparer(ref1_hash=ref1_hash, ref2_hash=ref2_hash, print_path=True)

comparer.setup()
comparer.diff_analyzer.display_diff_tree(comparer.dcmp)
Created temporary directory at /tmp/ref_compare___7utkph
ā”œ .github/
│ ā”œ actions/
│ │ ā”œ setup_env/
│ ā”œ workflows/
ā”œ arepo_data/
ā”œ atom_data/
│ ā”œ nlte_atom_data/
│ ā”œ stardis_atom_data/
ā”œ tardis/
│ ā”œ opacities/
│ │ ā”œ tests/
│ │ │ ā”œ test_tau_sobolev/
│ ā”œ plasma/
│ │ ā”œ equilibrium/
│ │ │ ā”œ tests/
│ │ │ │ ā”œ test_level_populations/
│ │ │ │ │ ā”œ test_level_population_solver/
│ │ │ │ ā”œ test_rate_matrix/
│ │ ā”œ tests/
│ │ │ ā”œ test_complete_plasmas/
│ │ │ │ ā”œ test_plasma/
│ │ │ │ │ ✱ plasma_unittest_disable_electron_scattering_False.h5
│ │ │ │ │ ✱ plasma_unittest_disable_electron_scattering_True.h5
│ │ │ │ │ ✱ plasma_unittest_excitation_dilute-lte.h5
│ │ │ │ │ ✱ plasma_unittest_excitation_lte.h5
│ │ │ │ │ ✱ plasma_unittest_helium_treatment_recomb-nlte.h5
│ │ │ │ │ ✱ plasma_unittest_helium_treatment_recomb-nlte_delta_treatment_0.5.h5
│ │ │ │ │ ✱ plasma_unittest_initial_t_inner_10000 K.h5
│ │ │ │ │ ✱ plasma_unittest_initial_t_rad_10000 K.h5
│ │ │ │ │ ✱ plasma_unittest_ionization_lte.h5
│ │ │ │ │ ✱ plasma_unittest_ionization_nebular.h5
│ │ │ │ │ ✱ plasma_unittest_line_interaction_type_downbranch.h5
│ │ │ │ │ ✱ plasma_unittest_line_interaction_type_macroatom.h5
│ │ │ │ │ ✱ plasma_unittest_line_interaction_type_scatter.h5
│ │ │ │ │ ✱ plasma_unittest_nlte.h5
│ │ │ │ │ ✱ plasma_unittest_nlte_classical_nebular.h5
│ │ │ │ │ ✱ plasma_unittest_nlte_coronal_approximation.h5
│ │ │ │ │ ✱ plasma_unittest_radiative_rates_type_blackbody.h5
│ │ │ │ │ ✱ plasma_unittest_radiative_rates_type_detailed.h5
│ │ │ │ │ ✱ plasma_unittest_radiative_rates_type_detailed_w_epsilon_1e-10.h5
│ │ │ │ │ ✱ plasma_unittest_radiative_rates_type_dilute-blackbody.h5
│ │ │ ā”œ test_hdf_plasma/
│ │ │ ā”œ test_nlte_excitation/
│ │ │ ā”œ test_nlte_solver/
│ │ │ ā”œ test_plasma_continuum/
│ │ │ ā”œ test_tardis_model_density_config/
│ ā”œ simulation/
│ │ ā”œ tests/
│ │ │ ā”œ test_simulation/
│ ā”œ spectrum/
│ │ ā”œ tests/
│ │ │ ā”œ test_spectrum_solver/
│ │ │ │ ā”œ test_spectrum_solver/
│ ā”œ tests/
│ │ ā”œ test_tardis_full/
│ │ │ ā”œ test_transport_simple/
│ │ ā”œ test_tardis_full_formal_integral/
│ │ │ ā”œ test_transport_simple_formal_integral/
│ ā”œ transport/
│ │ ā”œ montecarlo/
│ │ │ ā”œ tests/
│ │ │ │ ā”œ test_continuum/
│ │ │ │ ā”œ test_montecarlo_main_loop/
│ │ │ │ ā”œ test_packet_source/
│ │ │ │ │ ā”œ test_black_body_simple_source/
│ │ │ │ │ ā”œ test_black_body_simple_source_rel/
│ │ │ │ ā”œ test_rpacket_tracker/
│ │ │ │ ā”œ test_weighted_packet_source/
│ │ │ │ │ ā”œ test_black_body_weighted_source/
│ ā”œ visualization/
│ │ ā”œ tools/
│ │ │ ā”œ tests/
│ │ │ │ ā”œ test_liv_plot/
│ │ │ │ │ ā”œ test_liv_plotter/
│ │ │ │ ā”œ test_sdec_plot/
│ │ │ │ │ ā”œ test_sdec_plotter/
InĀ [6]:
comparer.compare()
Error comparing item: /simulation/plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /simulation/plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /simulation/plasma/yg_interp
unsupported operand type(s) for -: 'PchipInterpolator' and 'PchipInterpolator'
Error comparing item: /simulation/plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
==================================================
Summary for test_montecarlo_continuum.h5:
Total number of keys- in ref1: 148, in ref2: 148
Number of keys with different names in ref1 and ref2: 0
Number of keys with same name but different data in ref1 and ref2: 1
Number of totally same keys: 146
==================================================

Error comparing item: /simulation/plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'
Error comparing item: /simulation/plasma/dilute_planckian_radiation_field
No module named 'tardis.plasma.radiation_field'

Testing individual files¶

You can compare individual files too. Below example would work if you used example commits.

InĀ [7]:
# comparer.hdf_comparator.summarise_changes_hdf("test_generate_plot_ply__plotter_generate_plot_ply1__.h5",
#                                              Path(comparer.ref1_path) / "tardis/visualization/tools/tests/test_liv_plot/test_liv_plotter",
#                                              Path(comparer.ref2_path) / "tardis/visualization/tools/tests/test_liv_plot/test_liv_plotter"
#                                              )

HDF File Comparison¶

Below graph visualises all the HDF files that changed. Each block represents a key that changed, hovering on that block would show relative percentage change for that key.

InĀ [8]:
fig_same_name = comparer.generate_graph("different keys same name")
fig_different_keys = comparer.generate_graph("different keys")
Generating graph with updated hovertemplate
Generating graph with updated hovertemplate
InĀ [9]:
fig_different_keys
InĀ [10]:
fig_same_name.layout.width = 1000
fig_same_name

Spectrum Comparison¶

You can compare TARDIS spectra for the two commits and also provide a custom path for the spectra.

InĀ [11]:
comparer.compare_testspectrumsolver_hdf(
    custom_ref1_path=Path(comparer.ref1_path) / custom_ref1_spectrum_path, 
    custom_ref2_path=Path(comparer.ref2_path) / custom_ref2_spectrum_path
)
/home/runner/work/tardis/tardis/tardis-regression-data/compare.py:332: UserWarning:

This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.

No description has been provided for this image
InĀ [12]:
comparer.teardown()
Removed temporary directory /tmp/ref_compare___7utkph